/**
 * @author:稀饭
 * @time:上午10:41:07
 * @filename:JavaCloseTomcatRemote.java
 */
package JavaControlApplication;

import java.io.IOException;
import java.util.Date;

public class JavaCloseTomcatRemote {
	public void work() throws IOException {
		try {
			java.lang.Process p = java.lang.Runtime.getRuntime().exec("net stop \"Apache Tomcat\"");
			java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
			String s;
			String t = "成功停止";
			boolean restart = false;
			while ((s = in.readLine()) != null) {
				if (s.indexOf(t) != -1) {
					restart = true;
					break;
				}
			}
			System.out.println("<" + new Date() + "> Tomcat is stop " + (restart ? "OK" : "ERROR"));
		} catch (Exception e) {
			e.printStackTrace();
		}

		java.lang.Process p = java.lang.Runtime.getRuntime().exec("net start \"Apache Tomcat\"");
		java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
		String s;
		String t = "启动成功";
		boolean restart = false;
		while ((s = in.readLine()) != null) {
			if (s.indexOf(t) != -1) {
				restart = true;
				break;
			}
		}
	}

	public static void main(String[] args) throws IOException {
		new JavaCloseTomcatRemote().work();
	}
}
